<?php
	class cli 
	{
		private $color;
		private $cache;

		
                public function __construct ()
		{
			$this->color=0;
			$this->cache = '';
		}

		public function write($msg,$newline=true)
		{
			$msg = $this->colorize($msg);
			//I'm not sure which is faster....
			//echo ($newline) ? "$msg\n" : $msg;
			fputs(STDOUT,  ($newline) ? "$msg\n" : $msg);
		}

		public function setColor($color)
		{
			$this->color=$color;
		}
	
		public function addCache($txt,$colorSwitch=false)
		{
			if ($colorSwitch)
			{
				$this->cache .= $this->colorize($txt);
			}
			else
			{
				$this->cache .= $txt;
			}
		}

		public function writeCache()
		{
			$this->write($this->cache);
			$this->cache ='';
		}

		private function colorize($msg)
		{
			return "\033[".$this->color.'m '.$msg;
		}
	}
?>
